package com.xvjialing.lytech.weatherreport.service;

import com.xvjialing.lytech.weatherreport.bean.CityCode;
import com.xvjialing.lytech.weatherreport.repository.CityCodeRepository;
import com.xvjialing.lytech.weatherreport.utils.PageableUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityCodeService {

    @Autowired
    CityCodeRepository cityCodeRepository;

    public CityCode addCityCode(CityCode cityCode){
        return cityCodeRepository.save(cityCode);
    }

//    @Async
    public List<CityCode>  addCityCodeList(List<CityCode> cityCodeList){
         return cityCodeRepository.save(cityCodeList);
    }

    public Page<CityCode> findAllCityCode(int page){
        return cityCodeRepository.findAll(PageableUtils.getPageable(page));
    }

    public List<CityCode> findAllCityCode(){
        return cityCodeRepository.findAll();
    }

    public CityCode findById(long id){
        return cityCodeRepository.findOne(id);
    }

    public CityCode findByDescription(String description){
        return cityCodeRepository.findByDescription(description);
    }

    public CityCode findByCode(int code){
        return cityCodeRepository.findByCode(code);
    }
}